package org.microservice.system.controller;


import org.microservice.common.base.BaseControllerImpl;
import org.microservice.common.bean.PostVo;
import org.microservice.common.util.PageUtils;
import org.microservice.common.util.Query;
import org.microservice.common.util.R;
import org.microservice.system.dao.SysPostDao;
import org.microservice.system.service.SysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2018-09-04
 */

@RestController
@RequestMapping("/sysPost")
public class SysPostController extends BaseControllerImpl<SysPostDao,PostVo> {

    @Autowired
    private SysPostService sysPostService;



    public R getListPage(@RequestBody Map<String,Object> params){
        Query query = new Query(params);

        List<PostVo> sysPostLists =  sysPostService.getListPage(query);

        int total =sysPostService.getListPageTotal(query);

        PageUtils pageUtils = new PageUtils(sysPostLists, total, query.getLimit(), query.getCurrPage());

        return R.ok().put("data",pageUtils);

    }




    @RequestMapping("/getByName")
    public R getByName(@RequestParam("name") String name){
        List<PostVo> postVos = sysPostService.getByName(name);
        return R.ok().put("data",postVos);
    }


    @Override
    public R deleteById(@RequestParam("id") Serializable id) {
        sysPostService.updateDisabledById(Integer.parseInt(id.toString()));
        return R.ok();
    }
}